import pygame
from pygame.sprite import Sprite


class Bullet(Sprite):
    """飞船子弹"""
    def __init__(self, ai_setting, screen, ship):
        """初始化飞船子弹类并设置初始位置"""
        self.screen = screen
        self.ai_setting = ai_setting
        super(Bullet, self).__init__()

        #在（0,0）处创建一个子弹，再设置到飞船的头部
        self.rect = pygame.Rect(0, 0, ai_setting.bullet_width,ai_setting.bullet_height)
        self.rect.centerx = ship.rect.centerx
        self.rect.bottom = ship.rect.bottom - 40

        #用小数储存子弹位 置
        self.bot = float(self.rect.bottom)
        self.color = ai_setting.bullet_color
        self.speed_factor = ai_setting.bullet_speed_factor

    def update(self):
        #数据更新
        #更新子弹Y轴位置的小数值
        self.bot -= self.speed_factor
        #更新子弹Y轴的实际位置
        self.rect.bottom = self.bot

    def blitme(self):
        #屏幕显示更新
        pygame.draw.rect(self.screen, self.color, self.rect)

